package com.ruoyi.web.controller.trade;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trade.domain.TPairs;
import com.ruoyi.trade.service.ITPairsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交易对信息Controller
 *
 * @author sunye
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/trade/pairs")
public class TPairsController extends BaseController
{
    @Autowired
    private ITPairsService tPairsService;

    /**
     * 查询交易对信息列表
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPairs tPairs)
    {
        startPage();
        List<TPairs> list = tPairsService.selectTPairsList(tPairs);
        return getDataTable(list);
    }

    /**
     * 导出交易对信息列表
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:export')")
    @Log(title = "交易对信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPairs tPairs)
    {
        List<TPairs> list = tPairsService.selectTPairsList(tPairs);
        ExcelUtil<TPairs> util = new ExcelUtil<TPairs>(TPairs.class);
        util.exportExcel(response, list, "交易对信息数据");
    }

    /**
     * 获取交易对信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPairsService.selectTPairsById(id));
    }

    /**
     * 新增交易对信息
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:add')")
    @Log(title = "交易对信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPairs tPairs)
    {
        return toAjax(tPairsService.insertTPairs(tPairs));
    }

    /**
     * 修改交易对信息
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:edit')")
    @Log(title = "交易对信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPairs tPairs)
    {
        return toAjax(tPairsService.updateTPairs(tPairs));
    }

    /**
     * 删除交易对信息
     */
    @PreAuthorize("@ss.hasPermi('trade:pairs:remove')")
    @Log(title = "交易对信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPairsService.deleteTPairsByIds(ids));
    }
}
